package com.jrzh.mvc.controller.sys.ajax;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jrzh.framework.base.controller.BaseAjaxController;
import com.jrzh.framework.base.search.BaseSearch;
import com.jrzh.framework.bean.TreeViewBean;
import com.jrzh.mvc.model.sys.RoleModel;
import com.jrzh.mvc.search.sys.ResourcesSearch;
import com.jrzh.mvc.service.sys.manage.SysServiceManage;

@Controller(ResourcesController.LOCATION + "ResourcesController")
@RequestMapping(ResourcesController.LOCATION)
public class ResourcesController extends BaseAjaxController {
	public static final String LOCATION = "/sys/ajax/resource";
	
	@Autowired
	SysServiceManage sysServiceManage;

	@RequestMapping(method = RequestMethod.POST, value = "treeViewList")
	@ResponseBody
	public List<TreeViewBean> treeViewList(ResourcesSearch search) {
		log.info("123123123");
		List<TreeViewBean> treeList = new ArrayList<TreeViewBean>();
		search.setOrder(BaseSearch.Order_Type_Asc);
		search.setSort("createTime");
		search.setEqualIsDisable(false);
		try {
			String roleId = request.getParameter("roleId");
			RoleModel role = sysServiceManage.roleService.findById(roleId);
			treeList = sysServiceManage.resourcesService.getTreeByRole(search, role);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return treeList;
	}

	@Override
	protected void setData() {
		
	}
}
